package com.medical.Service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.medical.DTO.HealthDataDTO;
import com.medical.DTO.HealthDataPageDTO;
import com.medical.Mapper.HealthDataMapper;
import com.medical.Service.HealthDataService;
import com.medical.VO.HealthDataVO;
import com.medical.result.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class HealthDataServiceImpl implements HealthDataService {
    @Autowired
    private HealthDataMapper healthDataMapper;

    /**
     * 添加用户健康数据
     * @param healthDataDTO
     */
    @Override
    public void addHealthData(HealthDataDTO healthDataDTO) {
        healthDataDTO.setCreatedTime(LocalDateTime.now());
        healthDataDTO.setDate(LocalDateTime.now());
        healthDataMapper.insert(healthDataDTO);
    }

    /**
     * 删除用户健康数据
     * @param ids
     */
    @Override
    public void deleteHealthData(List<Integer> ids) {
        healthDataMapper.delete(ids);
    }

    /**
     * 修改用户健康数据
     * @param healthDataDTO
     */
    @Override
    public void updateHealthData(HealthDataDTO healthDataDTO) {
        healthDataMapper.update(healthDataDTO);
    }

    /**
     * 分页查询用户健康数据
     * @param healthDataPageDTO
     * @return
     */
    @Override
    public PageResult page(HealthDataPageDTO healthDataPageDTO) {
        PageHelper.startPage(healthDataPageDTO.getPage(),healthDataPageDTO.getPageSize());
       Page<HealthDataVO> page = healthDataMapper.pageSelect(healthDataPageDTO);
       PageResult pageResult = new PageResult(page.getTotal(),page.getResult());
       return pageResult;
    }
}
